class Solution(object):
    def digitsCount(self, d, low, high):
        """
        :type d: int
        :type low: int
        :type high: int
        :rtype: int
        """

        def search(value):
            num = value
            count = 0
            wait = []
            prefix = []
            while num // 10 > 0:
                if count == 0:
                    prefix.append(num % 10)
                else:
                    prefix.append(prefix[-1] + (num % 10) * 10 ** count)
                wait.append(num % 10)
                count += 1
                num = num // 10
            if count == 0:
                prefix.append(num % 10)
            else:
                prefix.append(prefix[-1] + (num % 10) * 10 ** count)
            count += 1
            wait.append(num)
            wait.reverse()
            prefix.reverse()
            DP = [0] * (count - 1)
            if count > 1:
                DP[0] = 1
                total = 1
            else:
                total = 0
            for i in range(1, count - 1):
                DP[i] = 10 * DP[i - 1] + 10 ** i
                if d != 0:
                    total += (9 * DP[i - 1] + 10 ** i)
                else:
                    total += 9 * DP[i - 1]
            DP.reverse()
            for i in range(count - 1):
                if d > 0:
                    if i == 0:
                        if wait[i] > d:
                            total += ((wait[i] - 1) * DP[i] + 10 ** (count - 1 - i))
                        else:
                            if wait[i] == d:
                                total += ((wait[i] - 1) * DP[i] + prefix[i + 1] + 1)
                            else:
                                total += ((wait[i] - 1) * DP[i])
                    else:
                        if wait[i] > d:
                            total += (wait[i] * DP[i] + 10 ** (count - 1 - i))
                        else:
                            if wait[i] == d:
                                total += (wait[i] * DP[i] + prefix[i + 1] + 1)
                            else:
                                total += (wait[i] * DP[i])
                else:
                    if i == 0:
                        total += ((wait[i] - 1) * DP[i])
                    else:
                        if wait[i] > d:
                            total += (wait[i] * DP[i] + 10 ** (count - 1 - i))
                        else:
                            total += (wait[i] * DP[i] + prefix[i + 1] + 1)
            if wait[-1] >= d:
                total += 1
            return total
        return search(high) - search(low - 1)


data = Solution()
d = 0
low = 1
high = 1000
print(data.digitsCount(d, low, high))
